<?php
/**
 * Created by PhpStorm.
 * User: 毛文科
 * Date: 2018\10\28 0028
 * Time: 10:03
 */
namespace app\admin\model;
use think\Db;

class GetDatas extends Db
{
    static public function create_model($str){
        $sur = Db::view($str)
            ->view('document','*',"document.id=$str.uid",'left');
        return $sur;
    }

    /**递归
     * @param $pid
     * @param int $num
     * @return array|\PDOStatement|string|\think\Collection
     */
    static public function diguiGetCate($pid,$num=0){
        $data = GetDatas::create_model('cate')->where('document.pid',$pid)->select();
        if($pid==0){
            $fidname = '最上级';
        }else{
            $file = Db::name('document')->where('id',$pid)->find();
            $fidname = $file['title'];
        }
        $nums = $num+1;
        foreach ($data as $key=>$value){
            $data[$key]['pidname'] = $fidname;
            $data[$key]['model_name']    = '栏目';
            $data[$key]['xxxxx']       = GetDatas::diguiGetCate($value['id'],$nums);
        }
        return $data;
    }
}